package leecode.二分法;

public class 寻找比目标字母大的最小字母 {
    public static void main(String[] args) {
        Solution solution = new Solution();
        char[] chars = new char[]{'a','a','a','b','b','b','b','c','c','c'};
        char b = solution.nextGreatestLetter(chars, 'b');
        System.out.println(b);


    }

    static class Solution {
        public char nextGreatestLetter(char[] letters, char target) {
            int lo = 0, hi = letters.length;
            while (lo < hi) {
                int mi = lo + (hi - lo) / 2;
                if (letters[mi] <= target) lo = mi + 1;
                else hi = mi;
            }
            return letters[lo % letters.length];


        }
    }
}
